const CodeString = require('./../../../define/CodeString');
const ErrorCode = require('./../../../define/ErrorCode');
const MAP_ID = require('./../../../define/MAP_ID');
const MsgCode = require('./../../../define/MsgCode');
const RoomState = require('./../../../define/RoomState');
let CardController = require('./CardController');

/**
 * 玩家操作操作类型
 * @type {Object}
 * */
let OperationType = {
    Xia: 0, // 下注
    Gen: 1, // 跟注
    Kan: 2, // 看牌
    Bi: 3,  // 比牌
    Jia: 4, // 加注
    Qi: 5,  // 弃牌
    GenDaoDi: 6, // 跟到底
};

/**
 * 房间基础类
 * @param {Number} room_id 房间ID
 * @param {Object} options  房间玩法选项
 * @param {Object} channelService
 * @param {Object} channel 房间通信信道（包含该房间所有玩家的会话信息）
 * */
let Room = function (room_id, options, channelService, channel) {
    /**
     * 房间的唯一ID
     * @protected
     * */
    this._room_id = room_id;

    /**
     * 房间玩法选项
     * @protected
     * */
    this._options = options;

    /**
     * 通信信道，所有的玩家都在这个通道中
     * @protected
     * */
    this._channel = channel;

    this._channelService = channelService;

    /**
     * 最大玩家数量
     * @protected
     * */
    this._max_palyers = 5;

    /**
     * 房间状态
     * @protected
     * */
    this._roomState = RoomState.Created;

    /**
     * 玩家数组
     * @protected
     * */
    this._players = [];

    /**
     * 玩家uid转玩家信息
     * @protected
     * */
    this._uid2info = {};

    /**
     * 可以操作的牌uids
     * */
    this._turnUids = [];

    /**
     * 操作总时间
     * @protected
     * */
    this._turn_time = 15;

    /**
     * 剩余操作时间
     * @protected
     * */
    this._residue_time = -1;

    /**
     * timerInteral
     * */
    this._turn_interval = null;

    /**
     * 房主uid
     * */
    this._house_owner_uid = null;

    /**
     * 当前局数
     * @protected
     * */
    this._current_round = 0;

    /**
     * 总局数
     * @protected
     * */
    this._total_round = 10;

    /**
     * 发牌的张数
     * @protected
     * */
    this._card_num = 3;

    /**
     * 发牌的数组，每个玩家都有一个牌数组
     * @protected
     * */
    this._uid2cards = {};

    /**
     * 每一局turn_uid转游戏数据
     * @protected
     * */
    this._uid2data = {};

    /**
     * 底分
     * @protected
     * */
    this._base_score = 1;

    /**
     * 当前倍数
     * @protected
     * */
    this._jia_score = 1;

    /**
     * 单局总分数
     * @protected
     * */
    this._round_total_score = 0;

    /**
     * 玩家uid对应的总分数
     * @protected
     * */
    this._uid2totalscore = {};

    /**
     * 发牌控制器
     * @protected
     * */
    this._card_controller = new CardController();

    /**
     * 每一局的数据
     * @protected
     * */
    this._round_data = [];

    /**
     * 游戏中每一局的数据
     * @type {Array}
     * @protected
     * */
    this._rounds_data = [];

    /**
     * 游戏玩家每一局的数据
     * @type {Object}
     * @protected
     * */
    this._players_data = {};

    /**
     * 最后操作的玩家uid
     * @protected
     * */
    this._on_turn_uid = null;

    /**
     * 位置对应表
     * @protected
     * */
    this._pos_map = {};

    for (let pos = 0; pos < this._max_palyers; pos++) {
        this._pos_map[pos] = '';
    }

    /**
     * 加注倍数
     * @param {Array}
     * */
    this._add_bets = [2, 3, 4, 5];

    /**
     * 当前路由
     * */
    this._currentRoute = 'onNotify';
};

/**
 * 获得一个可用的pos
 * @param {String | Number} uid
 * @return {Number}
 * */
Room.prototype.getPos = function (uid) {
    let p = -1;
    for (let pos in this._pos_map) {
        if (this._pos_map[pos] === '') {
            this._pos_map[pos] = uid;
            p = parseInt(pos);
            break;
        }
    }
    console.log('获得位置号【' + p + '】', this._pos_map);
    return p;
};

/**
 * 重置位置号
 * @param {Number} pos
 * */
Room.prototype.restorePos = function (pos) {
    if (typeof pos !== 'undefined') {
        this._pos_map[pos] = '';
        console.log('重置位置号【' + pos + '】', this._pos_map);
    }
};

/**
 * 向房间中添加玩家
 * @param {Object} info 玩家信息
 * @return {Boolean} 是否添加成功
 * */
Room.prototype.addPlayer = function (info) {
    let player = info;

    player['is_ready'] = false; // 默认不准备
    player['is_online'] = true; // 默认在线
    player['house_owner'] = false; // 默认不是房主

    if (this._players.length >= this._max_palyers) {
        return false;
    }
    // player['pos'] = this._players.length;
    player['pos'] = this.getPos(player['uid']);
    this._uid2info[player['uid']] = player;
    this._players.push(player);

    // 默认房间中的第一个人为房主
    if (this._players.length === 1) {
        player['house_owner'] = true;
        this._house_owner_uid = player['uid'];
    }
    console.log('房间【' + this._room_id + '】剩余人数【' + this._players.length + '】');

    return true;
};

/**
 * 从房间中删除指定uid的玩家
 * @param {String} uid 玩家uid
 * @return {Boolean} 房间中是否有该玩家
 * */
Room.prototype.removePlayer = function (uid) {
    // console.log("玩家【" + uid + "】离开房间【" + this._room_id + "】了");
    let index = -1;
    let i = 0;
    for (; i < this._players.length; i++) {
        let info = this._players[i];
        if (info['uid'] === uid) {
            index = i;
            break;
        }
    }

    if (index > -1) {
        delete this._uid2info[uid];
        this._uid2info[uid] = null;

        let infos = this._players.splice(index, 1);
        for (let j = 0; j < infos.length; j++) {
            this.restorePos(infos[j]['pos']);
            console.log('从房间【' + this._room_id + '】中删除玩家【' + infos[j]['uid'] + '】');
        }
        console.log('房间【' + this._room_id + '】剩余人数【' + this._players.length + '】');
    }
    return true;
};

/**
 * 获得房间中的玩家
 * @return {Object} 房间中的玩家信息数组
 * @public
 * */
Room.prototype.getPlayers = function () {
    return this._players;
};

/**
 * 获得当前房间中的玩家数量
 * @return {Number}
 * @public
 * */
Room.prototype.getPlayerCount = function () {
    return this._players.length;
};

/**
 * 是否可以销毁该房间
 * @return {Boolean} 是否可以摧毁
 * @public
 * */
Room.prototype.canDestroy = function () {
    return this._players.length === 0;
};

/**
 * 发送消息到客户端
 * @param {String | Number} code  消息号
 * @param {Object} data 消息数据
 * @param {Array} [uids] 接受的玩家ID，没有则广播
 * @protected
 * */
Room.prototype.send = function (code, data, uids) {
    let msgObj = {};
    msgObj.code = code;
    msgObj.data = data;

    if (typeof uids === 'undefined') {
        uids = this.getAllUid();
    }

    if (!Array.isArray(uids)) {
        uids = [uids];
    }

    console.log('send uids: ', uids);

    let receiver_list = [];
    for (let i = 0; i < uids.length; i++) {
        let obj = {};
        obj.uid = uids[i];
        let member = this._channel.getMember(uids[i]);
        if (member) {
            obj.sid = this._channel.getMember(uids[i])['sid'];
            receiver_list.push(obj);
        }
    }
    this._channelService.pushMessageByUids(this._currentRoute, msgObj, receiver_list);
};

/**
 * 收到客户端收到的通知
 * @param {Object} msg
 * @param {Object} session
 * @public
 * */
Room.prototype.onNotify = function (msg, session) {
    let self = this;
    let uid = msg['uid'];
    let code = msg['code'];
    let data = msg['data'];
    switch (code) {
        case MsgCode.StartGame:
            self.startGame();
            break;
        case MsgCode.Chat:
            self.chat(data);
            break;
        case MsgCode.Prepare:
            self.prepare(uid);
            break;
        case MsgCode.Operation:
            if (this._roomState === RoomState.Playing) {
                self.operation(data);
            }
            break;
        case MsgCode.LeaveRoom:
            self.leaveRoom(uid, session);
            break;
        default:
            console.log('没有处理【' + code + '】');
            break;
    }
};

Room.prototype.canLeaveRoom = function (uid) {
    if (this._roomState === RoomState.Playing) {
        return false;
    }
    return true;
};
/**
 * 有玩家离开房间
 * @param {String} uid
 * @param {Object} backendSession
 * @public
 * */
Room.prototype.leaveRoom = function (uid, backendSession) {
    this._channel.leave(uid, backendSession);

    this.removePlayer(uid);
    this.restorePos(this._uid2info.pos);

    delete this._uid2info[uid];
    this._uid2info[uid] = null;

    let data = {
        uid: uid,
        room_id: this._room_id,
        msg: CodeString[MsgCode.LeaveRoom]
    };

    this.send(MsgCode.LeaveRoom, data);
};

/**
 * 获得房间状态
 * @return {RoomState}
 * @public
 * */
Room.prototype.getRoomState = function () {
    return this._roomState;
};

/**
 * 获得该房间的room_id
 * @return {Number}
 * @public
 * */
Room.prototype.getRoomId = function () {
    return this._room_id;
};

/**
 * 聊天
 * @param {Object} data
 * */
Room.prototype.chat = function (data) {
    this.send(MsgCode.Chat, data);
};

/**
 * 广播准备状态
 * */
Room.prototype.prepare = function (uid) {
    this._uid2info[uid]['is_ready'] = true;
    let data = {
        uid: uid,
        room_id: this._room_id,
        is_ready: this._uid2info[uid]['is_ready'],
        msg: '广播准备状态'
    };
    this.send(MsgCode.Prepare, data);

    // 所有人准备好了，发送显示准备按钮
    let is_all_ready = true;
    for (let i = 0; i < this._players.length; i++) {
        if (!this._players[i]['is_ready']) {
            is_all_ready = false;
            break;
        }
    }
    if (is_all_ready && this.getPlayerCount() > 1) {
        this.send(MsgCode.ShowButtons, {'startgame': true}, this._house_owner_uid);
    } else {
        this.send(MsgCode.ShowButtons, {'startgame': false}, this._house_owner_uid);
    }
};

/**
 * 获得房间内所有玩家的uid
 * */
Room.prototype.getAllUid = function () {
    return Object.keys(this._uid2info);
};

/**
 * 获得除自己之外的所有uid
 * @param {String} turn_uid
 * @return {Array}
 * @protected
 * */
Room.prototype.getExceptTurnUidAllUid = function (turn_uid) {
    let all_uids = this.getAllUid();
    let index = all_uids.indexOf(turn_uid);
    if (index > -1) {
        all_uids.splice(index, 1);
    }
    return all_uids;
};

/**
 * 初始化可以turn的uid
 * @protected
 * */
Room.prototype._generateTurnUids = function () {
    this._turnUids = [];
    for (let i = 0; i < this._players.length; i++) {
        this._turnUids.push(this._players[i].uid);
        this._uid2totalscore[this._players[i].uid] = 0;
    }
    return this._turnUids;
};

/**
 * 获得一个可以turn的uid
 * 将turn到的uid放到数组的最后面去
 * */
Room.prototype.getTurnUid = function () {
    let turn_uid = this._turnUids.shift();
    this._turnUids.push(turn_uid);
    return turn_uid;
};

/**
 * 从可以turn的uid数组中删除指定的uid
 * @param {String} uid
 * */
Room.prototype.removeTurnUid = function (uid) {
    let index = this._turnUids.indexOf(uid);
    if (index > -1) {
        this._turnUids.splice(index, 1);
    }
};

/**
 * 开始游戏
 * @public
 * */
Room.prototype.startGame = function () {
    this._on_turn_uid = null;
    this._current_round++;
    this._roomState = RoomState.Playing;
    let data = {
        room_id: this._room_id,
        _roomState: this._roomState,
        msg: '开始游戏'
    };
    this.send(MsgCode.StartGame, data);
    this._initTurnData();
    this.dealCards();

    this.onTurn();
};

/**
 * 初始turn的数据结构
 * @protected
 * */
Room.prototype._initTurnData = function () {
    this._jia_score = 1;
    let uids = this._generateTurnUids();
    let uid2cards = this._generateCards(uids);

    this._uid2data = {};
    for (let i = 0; i < uids.length; i++) {
        this._uid2data[uids[i]] = {
            can_qi: true,
            can_gen: true,
            can_jia: true,
            is_kan: false,
            is_qi: false,
            cards: uid2cards[uids[i]],
            has_bet: 0,
            is_winner: false,
        };
    }

    console.log('_initTurnData:', this._uid2data);
    console.log('uid2cards:', this._uid2cards);
};

/**
 * 生成玩家的手牌
 * @param {Array} uids // 需要发牌的玩家数组
 * @protected
 * */
Room.prototype._generateCards = function (uids) {
    this._uid2cards = this._card_controller.shuffle(uids, this._card_num);
    console.log('生成玩家的手牌: ' + this._uid2cards);
    for (let uid in this._uid2cards) {
        let cards = this._uid2cards[uid];
        let card_obj = cards['card_obj'];
        console.log('uid【' + uid + '】', card_obj);
    }
    return this._uid2cards;
};

/**
 * 发牌
 * */
Room.prototype.dealCards = function () {
    this._roomState = RoomState.Playing;

    let deal_card_obj = {}; // 发牌的对象数据
    for (let uid in this._uid2cards) {
        deal_card_obj[uid] = [];
        let cards = this._uid2cards[uid];
        for (let i = 0; i < cards.length; i++) {
            deal_card_obj[uid].push(cards[i]);
        }
    }

    let data = {
        cards_obj: deal_card_obj,
        room_id: this._room_id,
        msg: '发牌咯'
    };
    this.send(MsgCode.DealCards, data);
};

/**
 * 轮到谁操作
 * @public
 * */
Room.prototype.onTurn = function () {
    this.startTurnInterval();

    let turn_uid = this.getTurnUid();
    let turn_time = 15;
    let can_qi = false;
    let can_bi = false;
    let can_jia = this._jia_score < this._add_bets[this._add_bets.length - 1];
    let can_gen = false;

    // 加注
    let jia_score = [2, 3, 4, 5];
    for (let i = 0; i < jia_score.length; i++) {
        // 如果当前加分倍数大于加注数组，则禁用加注按钮
        if (this._jia_score >= jia_score[i]) {
            jia_score[i] *= -1;
        }

        // 如果看过牌则加倍
        if (this._uid2data[turn_uid].is_kan) {
            jia_score[i] *= 2;
        }
    }

    // 跟分 = 底分 * 当前倍数
    let gen_score = this._base_score * this._jia_score;
    if (this._uid2data[turn_uid].is_kan) {
        gen_score = gen_score * 2;
    }

    // 1、给不该操作的玩家
    let other_data = {
        turn_uid: turn_uid,
        turn_time: this._turn_time,
        residue_time: this._residue_time,
        room_id: this._room_id
    };
    let other_uids = this.getExceptTurnUidAllUid(turn_uid);
    this.send(MsgCode.OnTurn, other_data, other_uids);

    // 2、给该操作的玩家
    let turn_data = {
        turn_uid: turn_uid,
        turn_time: turn_time,
        residue_time: this._residue_time,
        can_kan: !this._uid2data[turn_uid].is_kan,
        can_qi: can_qi,
        can_bi: can_bi,
        can_jia: can_jia,
        can_gen: can_gen,
        // bi_score: bi_score,
        bi_score: gen_score,
        gen_score: gen_score,
        jia_score: jia_score,
        room_id: this._room_id
    };
    this.send(MsgCode.OnTurn, turn_data, turn_uid);

    this._on_turn_uid = turn_uid;
};

Room.prototype.turnTimeOut = function () {
    this._residue_time = -1;
    console.log('操作超时了！');
};

Room.prototype.startTurnInterval = function () {
    this.clearTurnInterval();
    let self = this;
    this._residue_time = this._turn_time;
    this._turn_interval = setInterval(function () {
        --self._residue_time;
        if (self._residue_time < 0) {
            self.clearTurnInterval();
            self.turnTimeOut();
        }
    }, 1000);
};

Room.prototype.clearTurnInterval = function () {
    if (this._turn_interval) {
        clearInterval(this._turn_interval);
        this._turn_interval = null;
    }
    this._residue_time = -1;
};

/**
 * 玩家操作
 * @param {Object} data 玩家的操作数据
 * */
Room.prototype.operation = function (data) {
    let turn_uid = data['uid'];
    let type = data['type'];

    // 没有操作权限，操作部分功能的
    if (this._on_turn_uid !== turn_uid) {
        switch (type) {
            case OperationType.Kan:
                this.kan(data);
                console.log('玩家【' + turn_uid + '】看牌咯！');
                break;
            case OperationType.Qi:
                this.qi(data);
                console.log('玩家【' + turn_uid + '】弃牌咯！');
                break;
            case OperationType.GenDaoDi:
                console.log('玩家【' + turn_uid + '】跟到底！');
                break;
            default:
                break;
        }
        return;
    }

    this.clearTurnInterval();
    switch (type) {
        case OperationType.Qi:
            if (this.qi(data)) {
                this.onTurn();
            }
            break;
        case OperationType.Bi:
            this.bi(data);
            break;
        case OperationType.Jia:
            this.jia(data);
            break;
        case OperationType.Gen:
            this.gen(data);
            break;
        case OperationType.Kan:
            this.kan(data);
            break;
        default:
            console.log('没有处理该操作类型【' + type + '】');
            break;
    }
};

/**
 * 弃牌操作
 * @return {Boolean} 是否进入下一轮操作
 * */
Room.prototype.qi = function (data) {
    let uid = data['uid'];
    this._turnUids.remove(uid);
    let obj = {
        turn_uid: uid,
        type: OperationType.Qi,
        msg: '该玩家弃牌了！'
    };
    this.send(MsgCode.Operation, obj);
    this._turnUids.remove(uid);

    // 如果可操作的玩家数量小于2，则进入结算
    if (this._turnUids.length < 2) {
        this.settlement(this._turnUids.shift());
        return false;
    }
    return true;
};

/**
 * 比牌
 * @private
 * */
Room.prototype.bi = function (data) {
    if (this._turnUids.length < 2) {
        console.log('人数小于2不能比牌哟！');
        return false;
    }
    let turn_uid = data['uid'];
    let from_uid = data['from_uid'];
    let to_uid = data['to_uid'];

    if (typeof from_uid === 'undefined') {
        from_uid = turn_uid;
    }

    if (this._turnUids.length === 2) {
        to_uid = this._turnUids[0];
        if (from_uid !== this._turnUids[1]) {
            to_uid = this._turnUids[1];
        }
    }

    console.log('from_uid:', from_uid, ' | to_uid:', to_uid);

    let bi_score = this._base_score * this._jia_score;
    if (this._uid2data[turn_uid].is_kan) {
        bi_score *= 2;
    }
    this._round_total_score += bi_score;
    this._uid2data[from_uid].has_bet += bi_score;
    this._uid2data[from_uid].score += bi_score;

    // let from_cards = this._uid2data[from_uid].cards;
    // let to_cards = this._uid2data[to_uid].cards;
    let from_cards = this._uid2data[from_uid]['cards'].card_array;
    let to_cards = this._uid2data[to_uid]['cards'].card_array;
    let ret = this._card_controller.pkCards(from_cards, to_cards);
    let winner_uid = from_uid;
    let loser_uid = to_uid;
    if (!ret) {
        winner_uid = to_uid;
        loser_uid = from_uid;
    }
    let obj = {
        turn_uid: turn_uid,
        type: OperationType.Bi,
        bi_score: bi_score,
        round_bet: bi_score,
        winner_uid: winner_uid,
        loser_uid: loser_uid
    };
    this.send(MsgCode.Operation, obj);

    // 如果from是赢家，下一轮操作还是他，反则进入下一个玩家操作
    if (winner_uid === from_uid) {
        let last_turn_uid = this._turnUids.pop();
        this._turnUids.splice(0, 0, last_turn_uid);
    }

    this._uid2data[loser_uid].is_winner = false;

    // 可操作数组踢出输家
    this.removeTurnUid(loser_uid);
    if (this._turnUids.length > 1) {
        this.onTurn();
    } else {
        this._uid2data[from_uid].is_winner = true;
        this.settlement(winner_uid);
    }
};

/**
 * 全局比牌
 * @private
 * */
Room.prototype.globalBi = function () {
    console.log('全局比牌');
};

/**
 * 加注
 * @private
 * */
Room.prototype.jia = function (data) {
    let turn_uid = data['uid'];

    if (!data['jia_score'] || data['jia_score'] > this._add_bets[this._add_bets.length - 1]) {
        console.log('不符合加注规则！');
        return false;
    }

    this._jia_score = data['jia_score'];

    let jia_score = this._base_score * this._jia_score;
    if (this._uid2data[turn_uid].is_kan) {
        jia_score *= 2;
    }
    this._round_total_score += jia_score;
    this._uid2data[turn_uid].has_bet += jia_score;

    let obj = {
        turn_uid: turn_uid,
        type: OperationType.Jia,
        jia_score: jia_score,
        round_bet: jia_score,
        total_score: this._round_total_score
    };
    this.send(MsgCode.Operation, obj);

    this.onTurn();
};

/**
 * 跟注
 * @param {Object} data
 * @private
 * */
Room.prototype.gen = function (data) {
    let turn_uid = data['uid'];
    let gen_score = this._base_score * this._jia_score;
    if (this._uid2data[turn_uid].is_kan) {
        gen_score *= 2;
    }
    this._round_total_score += gen_score;
    this._uid2data[turn_uid].has_bet += gen_score;

    let obj = {
        turn_uid: turn_uid,
        type: OperationType.Gen,
        gen_score: gen_score,
        round_bet: gen_score,
        total_score: this._round_total_score,
    };
    this.send(MsgCode.Operation, obj);

    this.onTurn();
};

/**
 * 看牌
 * @private
 * */
Room.prototype.kan = function (data) {
    let turn_uid = data['uid'];

    this._uid2data[turn_uid].is_kan = true;

    let obj = {
        turn_uid: turn_uid,
        type: OperationType.Kan,
        card_array: this._uid2data[turn_uid]['cards'].card_array,
        card_type: this._uid2data[turn_uid]['cards'].card_type,
        card_type_des: this._uid2data[turn_uid]['cards'].card_type_des,
    };
    this.send(MsgCode.Operation, obj, turn_uid);

    let other = {
        turn_uid: turn_uid,
        type: OperationType.Kan
    };
    let other_uids = this.getExceptTurnUidAllUid(turn_uid);
    this.send(MsgCode.Operation, other, other_uids);

    // 如果自己是当前操作的玩家，则需要刷新显示数据
    if (this._on_turn_uid === turn_uid) {
        this._turnUids.pop();
        this._turnUids.splice(0, 0, this._on_turn_uid);
        this.onTurn();
    }
};

/**
 * 小结算
 * @param {String | Number} winner_uid
 * @protected
 * */
Room.prototype.settlement = function (winner_uid) {
    this.clearTurnInterval();
    if (!winner_uid) {
        console.log('传入赢家的uid为空！');
        return false;
    }
    this._roomState = RoomState.Settlement;

    // 单局结算发往客户端的数据
    let data = {};
    data.room_state = this._roomState;
    data.winner_uid = winner_uid;
    data.infos = [];

    // 每一局的数据
    let round_data = [];
    for (let i = 0; i < this._players.length; i++) {
        // 还原准备状态
        this._players[i].is_ready = false;
        let uid = this._players[i].uid;
        let has_bet = this._uid2data[uid].has_bet;

        // 每一个人的数据
        let player = {};
        player.uid = uid;
        player.sex = this._players[i].sex;
        player.headimgurl = this._players[i].headimgurl;
        player.current_round = this._current_round;
        player.is_winner = winner_uid === uid;
        player.score = has_bet;
        if (player.is_winner) {
            player.score *= -1;
        }
        round_data.push(player);

        // 总分数
        this._uid2totalscore[uid] += player.score;

        // 发送到客户端单局结算的数据
        let info = {
            uid: uid,
            total_score: this._uid2totalscore[uid]
        };
        data.infos.push(info);

        // 按玩家uid组成的数据
        if (!this._players_data[uid]) {
            this._players_data[uid] = {
                uid: uid,
                headimgurl: player.headimgurl,
                sex: player.sex,
                rounds: [],
                total_score: 0
            };
        }
        this._players_data[uid].total_score += player.score;
        this._players_data[uid].rounds.push({
            current_round: player.current_round,
            is_winner: player.is_winner,
            score: player.score
        });
    }
    this._rounds_data.push(round_data);

    this.send(MsgCode.Settlement, data);

    // 判断是否触发总结算
    if (this._current_round >= this._total_round) {
        this.totalSettlement();
    } else {
        // 显示准备按钮
        this._roomState = RoomState.Prepare;
        this.send(MsgCode.ShowButtons, {_roomState: this._roomState, preapre: true});
    }
};

/**
 * 大结算
 * @protected
 * */
Room.prototype.totalSettlement = function () {
    this.clearTurnInterval();
    this._roomState = RoomState.TotalSettlement;
    let data = {};
    data['room_state'] = this._roomState;
    data.players_data = this._players_data;
    this.send(MsgCode.TotalSettlement, data);

    // 销毁该房间，将所有人从该房间踢出
};

module.exports = Room;